﻿Imports System.Net.Mail
Imports MyIPBssLogic.AppConfig
Imports System.Net

Public Class MailSender

    Private _MyConf As MailConfig

    Public Sub New(ByVal MyConf As MailConfig)

        _MyConf = MyConf

    End Sub


    Public Function SendMessage() As Boolean

        Try
            Dim from As New System.Net.Mail.MailAddress(_MyConf.From.MailBox, _MyConf.From.DisplayName)
            Dim ToMail As New System.Net.Mail.MailAddress(_MyConf.To.MailBox)

            Dim message As New MailMessage(from, _
                                           ToMail)

            message.Subject = _MyConf.Email.Subject
            message.Body = _MyConf.Email.Body

            Dim emailClient As New SmtpClient(_MyConf.From.NameSever, _
                                              _MyConf.From.Port)
            If _MyConf.From.Secure Then

                emailClient.Credentials = New System.Net.NetworkCredential(_MyConf.From.User, _MyConf.From.Password)

            End If

            emailClient.Send(message)

            Return True

        Catch ex As Exception

            Return False

        End Try


    End Function


End Class
